package com.patterns.singleton;

/**
 * @Author Tanyu
 * @Date 2020/6/2 9:53
 * @Description 双重检查锁 双重检测锁式：涉及到JVM底层内部模型，偶尔会出问题。不建议使用
 * @Version 1.0
 */
public class SingletonLazyDoubleCheckLock {

  private static SingletonLazyDoubleCheckLock singleton = null;

  private SingletonLazyDoubleCheckLock() {
  }

  public static SingletonLazyDoubleCheckLock getInstance() {
    if (singleton == null) {
      SingletonLazyDoubleCheckLock sc;
      synchronized (SingletonLazyDoubleCheckLock.class) {
        sc = singleton;
        if (sc == null) {
          synchronized (SingletonLazyDoubleCheckLock.class) {
            if (sc == null) {
              sc = new SingletonLazyDoubleCheckLock();
            }
          }
          singleton = sc;
        }
      }
    }
    return singleton;
  }

}
